package com.fsnbigdata.repository;
import io.springlets.data.jpa.repository.support.QueryDslRepositorySupportExt;
import org.springframework.roo.addon.layers.repository.jpa.annotations.RooJpaRepositoryCustomImpl;
import com.fsnbigdata.domain.ParkDistrictOrganism;
import com.fsnbigdata.domain.ParkDistrict;
import com.fsnbigdata.domain.QParkDistrictOrganism;
import com.querydsl.core.types.Path;
import com.querydsl.jpa.JPQLQuery;
import io.springlets.data.domain.GlobalSearch;
import io.springlets.data.jpa.repository.support.QueryDslRepositorySupportExt.AttributeMappingBuilder;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;

/**
 * = ParkDistrictOrganismRepositoryImpl
 *
 * TODO Auto-generated class documentation
 *
 */
@RooJpaRepositoryCustomImpl(repository = ParkDistrictOrganismRepositoryCustom.class)
@Transactional(readOnly = true)
public class ParkDistrictOrganismRepositoryImpl extends QueryDslRepositorySupportExt<ParkDistrictOrganism> implements ParkDistrictOrganismRepositoryCustom {

    /**
     * TODO Auto-generated constructor documentation
     */
    ParkDistrictOrganismRepositoryImpl() {
        super(ParkDistrictOrganism.class);
    }

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String IMAGE = "image";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String PARK_DISTRICT = "parkDistrict";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String LATIN_NAME = "latinName";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String ORGANISM_ID = "organismId";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String NAME = "name";

    /**
     * TODO Auto-generated method documentation
     *
     * @param parkDistrict
     * @param globalSearch
     * @param pageable
     * @return Page
     */
    public Page<ParkDistrictOrganism> findByParkDistrict(ParkDistrict parkDistrict, GlobalSearch globalSearch, Pageable pageable) {
        QParkDistrictOrganism parkDistrictOrganism = QParkDistrictOrganism.parkDistrictOrganism;
        JPQLQuery<ParkDistrictOrganism> query = from(parkDistrictOrganism);
        Assert.notNull(parkDistrict, "parkDistrict is required");
        query.where(parkDistrictOrganism.parkDistrict.eq(parkDistrict));
        Path<?>[] paths = new Path<?>[] { parkDistrictOrganism.parkDistrict, parkDistrictOrganism.name, parkDistrictOrganism.latinName, parkDistrictOrganism.image, parkDistrictOrganism.organismId };
        applyGlobalSearch(globalSearch, query, paths);
        AttributeMappingBuilder mapping = buildMapper().map(PARK_DISTRICT, parkDistrictOrganism.parkDistrict).map(NAME, parkDistrictOrganism.name).map(LATIN_NAME, parkDistrictOrganism.latinName).map(IMAGE, parkDistrictOrganism.image).map(ORGANISM_ID, parkDistrictOrganism.organismId);
        applyPagination(pageable, query, mapping);
        applyOrderById(query);
        return loadPage(query, pageable, parkDistrictOrganism);
    }
}
